/**
 * 
 */
package edu.uoc.tdp.client.pantalles;


import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JLabel;

import edu.uoc.tdp.client.Client;
import edu.uoc.tdp.client.EnumRol;
import edu.uoc.tdp.client.comu.Util;
import edu.uoc.tdp.client.gestors.GestorConsultaEvent;
import edu.uoc.tdp.client.gestors.GestorEscriptori;
import edu.uoc.tdp.client.gestors.GestorEvent;
import edu.uoc.tdp.client.gestors.GestorMantenimient;
import edu.uoc.tdp.client.gestors.GestorRMI;
import edu.uoc.tdp.comu.beans.Event;
//import edu.uoc.tdp.comu.beans.EventAux;
import edu.uoc.tdp.comu.beans.CentreDocent;
import edu.uoc.tdp.comu.beans.Pais;
import edu.uoc.tdp.comu.beans.TipusEvent;
import edu.uoc.tdp.comu.beans.Universitat;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Rectangle;
import java.rmi.RemoteException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JCheckBox;
import javax.swing.JButton;

/**
 * @author Tomeu Antich
 *
 */
public class PantallaEvent extends JPanel {

	private static final long serialVersionUID = 1L;
	private Vector<TipusEvent> TipusEventVector = new Vector<TipusEvent>(); //
	private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
	private JLabel jLabelTitol = null;
	private JLabel jLabelCentreDocent = null;
	private JTextField jTextFieldCentreDocent = null;
	private JLabel jLabelCodiCentre = null;
	private JTextField jTextFieldCodiCentre = null;
	private JLabel jLabelDadesEvent = null;
	private JLabel jLabelNomEvent = null;
	private JLabel jLabelInici = null;
	private JLabel jLabelFi = null;
	private JLabel jLabelTipus = null;
	private JLabel jLabelIncripcio = null;
	private JLabel jLabelInscripciolimit = null;
	private JLabel jLabelDescripcio = null;
	private JLabel jLabelpercentMinNoModif = null;
	private JLabel jLabelPreu = null;
	private JLabel jLabelPlaces = null;
	private JLabel jLabelPlacesxRol = null;
	private JLabel jLabelPrerequisits = null;
	private JTextField jTextFieldNom = null;
	private JComboBox jComboBoxTipusEvent = null;
	private JTextField jTextFieldDataInici = null;
	private JTextField jTextFieldDataFi = null;
	private JTextField jTextFieldInscripcioInici = null;
	private JTextField jTextFieldInscripcioFi = null;
	private JTextField jTextFieldPreu = null;
	private JTextField jTextFieldPercentMinNoModif = null;
	private JTextField jTextFieldPlaces = null;
	private JTextArea jTextAreaDescripcio = null;
	private JTable jTablePrerequisits = null;
	private JCheckBox jCheckBoxEstudiant = null;
	private JCheckBox jCheckBoxDocent = null;
	private JCheckBox jCheckBoxNoDocent = null;
	private JCheckBox jCheckBoxAltres = null;
	private JLabel jLabelEstudiant = null;
	private JLabel jLabelDocent = null;
	private JLabel jLabelNoDocent = null;
	private JLabel jLabelAltres = null;
	private JScrollPane jScrollPanePrerequisits = null;
	private JButton jButtonDesar = null;
	private JButton jButtonSortir = null;
	private JButton jButtonModificaPrerequisits = null;
	private JCheckBox jCheckBoxActiu = null;
	private JLabel jLabelActiu = null;
	private JButton jButtonBorrarCamps = null;
	private static int NOU = 1;
	private static int MODIFICAR = 2;
	private static int VEURE = 3;
	private int operacio = 0;
	private int iEv = 0;
	
	
	/**
	 * This is the default constructor
	 */
	public PantallaEvent() {
		super();
		initialize();
		GestorEvent.CarregaTipusEvent(jComboBoxTipusEvent, TipusEventVector);
		jTextFieldCodiCentre.setText(Integer.toString(Client.usuariConnectat.getId_Centre()));
		jTextFieldCentreDocent.setText(Client.usuariConnectat.getCentreDocent().getNom());
	}

	public PantallaEvent(int id_event) {
		super();
		initialize();
		this.iEv=id_event;
		GestorEvent.CarregaTipusEvent(jComboBoxTipusEvent, TipusEventVector);
		jTextFieldCodiCentre.setText(Integer.toString(Client.usuariConnectat.getId_Centre()));
		jTextFieldCentreDocent.setText(Client.usuariConnectat.getCentreDocent().getNom());
	//	this.omplirEvent(id_event);
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		

		jLabelActiu = new JLabel();
		jLabelActiu.setBounds(new Rectangle(44, 319, 100, 16));
		jLabelActiu.setText(Util.GetEtiqueta("Event.gestio.Actiu"));
		jLabelAltres = new JLabel();
		jLabelAltres.setBounds(new Rectangle(520, 313, 100, 16));
		jLabelAltres.setText(Util.GetEtiqueta("Event.gestio.Altres"));
		jLabelNoDocent = new JLabel();
		jLabelNoDocent.setBounds(new Rectangle(520, 283, 150, 16));
		jLabelNoDocent.setText(Util.GetEtiqueta("Event.gestio.NoDocent"));
		jLabelDocent = new JLabel();
		jLabelDocent.setBounds(new Rectangle(520, 253, 100, 16));
		jLabelDocent.setText(Util.GetEtiqueta("Event.gestio.Docent"));
		jLabelEstudiant = new JLabel();
		jLabelEstudiant.setBounds(new Rectangle(520, 223, 100, 16));
		jLabelEstudiant.setText(Util.GetEtiqueta("Event.gestio.Estudiant"));
		jLabelPrerequisits = new JLabel();
		jLabelPrerequisits.setBounds(new Rectangle(290, 195, 100, 16));
		jLabelPrerequisits.setText(Util.GetEtiqueta("Event.gestio.prerequisits"));
		jLabelPlacesxRol = new JLabel();
		jLabelPlacesxRol.setBounds(new Rectangle(497, 195, 100, 16));
		jLabelPlacesxRol.setText(Util.GetEtiqueta("Event.gestio.PlacesxRol"));
		jLabelPlaces = new JLabel();
		jLabelPlaces.setBounds(new Rectangle(165, 255, 100, 16));
		jLabelPlaces.setText(Util.GetEtiqueta("Event.gestio.Places"));
		jLabelPreu = new JLabel();
		jLabelPreu.setBounds(new Rectangle(16, 255, 100, 16));
		jLabelPreu.setText(Util.GetEtiqueta("Event.gestio.Preu"));
		jLabelpercentMinNoModif = new JLabel();
		jLabelpercentMinNoModif.setBounds(new Rectangle(16, 287, 150, 16));
		jLabelpercentMinNoModif.setText(Util.GetEtiqueta("Event.gestio.percentMinNoModif"));
		jLabelDescripcio = new JLabel();
		jLabelDescripcio.setBounds(new Rectangle(16, 140, 100, 16));
		jLabelDescripcio.setText(Util.GetEtiqueta("Event.gestio.Descripcio"));
		jLabelInscripciolimit = new JLabel();
		jLabelInscripciolimit.setBounds(new Rectangle(195, 225, 100, 16));
		jLabelInscripciolimit.setText(Util.GetEtiqueta("Event.gestio.InscripcioLimit"));
		jLabelIncripcio = new JLabel();
		jLabelIncripcio.setBounds(new Rectangle(16, 225, 150, 16));
		jLabelIncripcio.setText(Util.GetEtiqueta("Event.gestio.Incripcio"));
		jLabelTipus = new JLabel();
		jLabelTipus.setBounds(new Rectangle(425, 106, 100, 16));
		jLabelTipus.setText(Util.GetEtiqueta("Event.gestio.TipusEvent"));
		jLabelFi = new JLabel();
		jLabelFi.setBounds(new Rectangle(195, 196, 100, 16));
		jLabelFi.setText(Util.GetEtiqueta("Event.gestio.DataFi"));
		jLabelInici = new JLabel();
		jLabelInici.setBounds(new Rectangle(16, 195, 150, 16));
		jLabelInici.setText(Util.GetEtiqueta("Event.gestio.DataInici"));
		jLabelNomEvent = new JLabel();
		jLabelNomEvent.setBounds(new Rectangle(16, 106, 100, 16));
		jLabelNomEvent.setText(Util.GetEtiqueta("Event.gestio.NomEvent"));
		jLabelDadesEvent = new JLabel();
		jLabelDadesEvent.setFont(new Font("Dialog", Font.BOLD, 16));
		jLabelDadesEvent.setBounds(new Rectangle(15, 75, 200, 16));
		jLabelDadesEvent.setText(Util.GetEtiqueta("Event.gestio.DadesEvent"));
		jLabelCodiCentre = new JLabel();
		jLabelCodiCentre.setBounds(new Rectangle(469, 47, 100, 16));
		jLabelCodiCentre.setText(Util.GetEtiqueta("Event.gestio.CodiCentre"));
		jLabelCentreDocent = new JLabel();
		jLabelCentreDocent.setBounds(new Rectangle(15, 45, 200, 16));
		jLabelCentreDocent.setText(Util.GetEtiqueta("Event.gestio.CentreDocent"));
		jLabelTitol = new JLabel();
		jLabelTitol.setFont(new Font("Dialog", Font.BOLD, 16));
		jLabelTitol.setText(Util.GetEtiqueta("Event.gestio.titol"));
		jLabelTitol.setBounds(new Rectangle(15, 15, 200, 16));
		this.setSize(640, 380);
		this.setLayout(null);
		this.add(jLabelTitol, null);
		this.add(jLabelCentreDocent, null);
		this.add(getJTextFieldCentreDocent(), null);
		this.add(jLabelCodiCentre, null);
		this.add(getJTextFieldCodiCentre(), null);
		this.add(jLabelDadesEvent, null);
		this.add(jLabelNomEvent, null);
		this.add(jLabelInici, null);
		this.add(jLabelFi, null);
		this.add(jLabelTipus, null);
		this.add(jLabelIncripcio, null);
		this.add(jLabelInscripciolimit, null);
		this.add(jLabelDescripcio, null);
		this.add(jLabelpercentMinNoModif, null);
		this.add(jLabelPreu, null);
		this.add(jLabelPlaces, null);
		this.add(jLabelPlacesxRol, null);
		this.add(jLabelPrerequisits, null);
		this.add(getJTextFieldNom(), null);
		this.add(getJComboBoxTipusEvent(), null);
		this.add(getJTextFieldDataInici(), null);
		this.add(getJTextFieldDataFi(), null);
		this.add(getJTextFieldInscripcioInici(), null);
		this.add(getJTextFieldInscripcioFi(), null);
		this.add(getJTextFieldPreu(), null);
		this.add(getJTextFieldPercentMinNoModif(), null);
		this.add(getJTextFieldPlaces(), null);
		this.add(getJTextAreaDescripcio(), null);
		this.add(getJCheckBoxEstudiant(), null);
		this.add(getJCheckBoxDocent(), null);
		this.add(getJCheckBoxNoDocent(), null);
		this.add(getJCheckBoxAltres(), null);
		this.add(jLabelEstudiant, null);
		this.add(jLabelDocent, null);
		this.add(jLabelNoDocent, null);
		this.add(jLabelAltres, null);
		this.add(getJScrollPanePrerequisits(), null);
		this.add(getJButtonDesar(), null);
		this.add(getJButtonSortir(), null);
		this.add(getJButtonModificaPrerequisits(), null);
		this.add(getJCheckBoxActiu(), null);
		this.add(jLabelActiu, null);
		this.add(getJButtonBorrarCamps(), null);
		
		//NOU EVENT
//		if (operacio == NOU){
//			NouEvent();
//		}
//		if (operacio == MODIFICAR){
//			ModificacioEvent(id_event);
//		}
//		if (operacio == VEURE){
//			VeureEvent(id_event);
//		}
		
	}

	/**
	 * This method initializes jTextFieldCentreDocent	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCentreDocent() {
		if (jTextFieldCentreDocent == null) {
			jTextFieldCentreDocent = new JTextField();
			jTextFieldCentreDocent.setBounds(new Rectangle(120, 45, 320, 20));
		}
		return jTextFieldCentreDocent;
	}

	/**
	 * This method initializes jTextFieldCodiCentre	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCodiCentre() {
		if (jTextFieldCodiCentre == null) {
			jTextFieldCodiCentre = new JTextField();
			jTextFieldCodiCentre.setBounds(new Rectangle(520, 46, 90, 20));
		}
		return jTextFieldCodiCentre;
	}

	/**
	 * This method initializes jTextFieldNom	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldNom() {
		if (jTextFieldNom == null) {
			jTextFieldNom = new JTextField();
			jTextFieldNom.setBounds(new Rectangle(70, 105, 330, 20));
		}
		return jTextFieldNom;
	}

	/**
	 * This method initializes jComboBoxTipusEvent	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxTipusEvent() {
		if (jComboBoxTipusEvent == null) {
			jComboBoxTipusEvent = new JComboBox();
			jComboBoxTipusEvent.setBounds(new Rectangle(462, 106, 151, 21));
		}
		return jComboBoxTipusEvent;
	}

	
	/**
	 * This method initializes jTextFieldDataInici	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldDataInici() {
		if (jTextFieldDataInici == null) {
			jTextFieldDataInici = new JTextField();
			jTextFieldDataInici.setBounds(new Rectangle(120, 195, 70, 20));
		}
		return jTextFieldDataInici;
	}

	/**
	 * This method initializes jTextFieldDataFi	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldDataFi() {
		if (jTextFieldDataFi == null) {
			jTextFieldDataFi = new JTextField();
			jTextFieldDataFi.setBounds(new Rectangle(205, 195, 70, 20));
		}
		return jTextFieldDataFi;
	}

	/**
	 * This method initializes jTextFieldInscripcioInici	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldInscripcioInici() {
		if (jTextFieldInscripcioInici == null) {
			jTextFieldInscripcioInici = new JTextField();
			jTextFieldInscripcioInici.setBounds(new Rectangle(120, 225, 70, 20));
		}
		return jTextFieldInscripcioInici;
	}

	/**
	 * This method initializes jTextFieldinscripcioFi	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldInscripcioFi() {
		if (jTextFieldInscripcioFi == null) {
			jTextFieldInscripcioFi = new JTextField();
			jTextFieldInscripcioFi.setBounds(new Rectangle(205, 225, 70, 20));
		}
		return jTextFieldInscripcioFi;
	}

	/**
	 * This method initializes jTextFieldPreu	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPreu() {
		if (jTextFieldPreu == null) {
			jTextFieldPreu = new JTextField();
			jTextFieldPreu.setBounds(new Rectangle(66, 254, 64, 20));
		}
		return jTextFieldPreu;
	}

	/**
	 * This method initializes jTextFieldPercentMinNoModif	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPercentMinNoModif() {
		if (jTextFieldPercentMinNoModif == null) {
			jTextFieldPercentMinNoModif = new JTextField();
			jTextFieldPercentMinNoModif.setBounds(new Rectangle(170, 287, 36, 20));
		}
		return jTextFieldPercentMinNoModif;
	}

	/**
	 * This method initializes jTextFieldPlaces	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPlaces() {
		if (jTextFieldPlaces == null) {
			jTextFieldPlaces = new JTextField();
			jTextFieldPlaces.setBounds(new Rectangle(220, 255, 38, 20));
		}
		return jTextFieldPlaces;
	}

	/**
	 * This method initializes jTextAreaDescripcio	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextAreaDescripcio() {
		if (jTextAreaDescripcio == null) {
			jTextAreaDescripcio = new JTextArea();
			jTextAreaDescripcio.setBounds(new Rectangle(95, 141, 520, 38));
		}
		return jTextAreaDescripcio;
	}


	/**
	 * This method initializes jCheckBoxEstudiant	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBoxEstudiant() {
		if (jCheckBoxEstudiant == null) {
			jCheckBoxEstudiant = new JCheckBox();
			jCheckBoxEstudiant.setBounds(new Rectangle(497, 220, 21, 21));
		}
		return jCheckBoxEstudiant;
	}

	/**
	 * This method initializes jCheckBoxDocent	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBoxDocent() {
		if (jCheckBoxDocent == null) {
			jCheckBoxDocent = new JCheckBox();
			jCheckBoxDocent.setBounds(new Rectangle(497, 250, 21, 21));
		}
		return jCheckBoxDocent;
	}

	/**
	 * This method initializes jCheckBoxNoDocent	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBoxNoDocent() {
		if (jCheckBoxNoDocent == null) {
			jCheckBoxNoDocent = new JCheckBox();
			jCheckBoxNoDocent.setBounds(new Rectangle(497, 280, 21, 21));
		}
		return jCheckBoxNoDocent;
	}

	/**
	 * This method initializes jCheckBoxAltres	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBoxAltres() {
		if (jCheckBoxAltres == null) {
			jCheckBoxAltres = new JCheckBox();
			jCheckBoxAltres.setBounds(new Rectangle(497, 310, 21, 21));
		}
		return jCheckBoxAltres;
	}

	/**
	 * This method initializes jScrollPanePrerequisits	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPanePrerequisits() {
		if (jScrollPanePrerequisits == null) {
			jScrollPanePrerequisits = new JScrollPane();
			jScrollPanePrerequisits.setBounds(new Rectangle(290, 225, 175, 90));
			jScrollPanePrerequisits.setViewportView(getJTablePrerequisit());
		}
		return jScrollPanePrerequisits;
	}

	/**
	 * This method initializes jTablePrerequisit	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTablePrerequisit() {
		if (jTablePrerequisits == null) {
			jTablePrerequisits = new JTable();
		}
		return jTablePrerequisits;
	}

	/**
	 * This method initializes jButtonDesar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonDesar() {
		if (jButtonDesar == null) {
			jButtonDesar = new JButton();
			jButtonDesar.setBounds(new Rectangle(510, 350, 100, 25));
			jButtonDesar.setText(Util.GetEtiqueta("Event.gestio.desar"));	
			jButtonDesar.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
					this.GravarDades();
				}
			
			private void GravarDades() {
				Event e = new Event();										
	//			e.setId_event(iEv);
				e.setNom(jTextFieldNom.getText());
				e.setDescripcio(jTextAreaDescripcio.getText());
				try {
				e.setDataIni(sdf.parse(jTextFieldDataInici.getText()));
				e.setDataFi(sdf.parse(jTextFieldDataFi.getText()));
				e.setDataIniInscripcio(sdf.parse(jTextFieldInscripcioInici.getText()));
				e.setCapacitatMax(Integer.parseInt(jTextFieldPlaces.getText()));
				e.setId_centre(Integer.parseInt(jTextFieldCodiCentre.getText()));
				e.setDataFiInscripcio(sdf.parse(jTextFieldInscripcioFi.getText())); }
				catch (ParseException e1){
					Util.MissatgeError(Util.GetEtiqueta("Errada,data"));
				}
				
				e.setId_tipusevent(jComboBoxTipusEvent.getSelectedIndex());
				e.setPreu(Double.parseDouble(jTextFieldPreu.getText()));
				e.setPercentMinNoModif(Double.parseDouble(jTextFieldPercentMinNoModif.getText()));		
				e.setActiu(jCheckBoxActiu.isSelected());
				
				
				try {

					if(iEv==0){

						GestorRMI.rmi.altaEvent(e);
					}
					else{
						GestorRMI.rmi.modificarEvent(e);
					}

					Util.MissatgeAvis(Util.GetEtiqueta("ConsultaConcepte.RegistreGrabat"));
				}
				catch (Exception ex) {
					Util.MissatgeError(Util.GetEtiqueta("ErrorConnexio"));
				}
				
			
				Client.escriptori.DeixarEscriptoriSensePanells();	
		}		
			
			});
		}
		return jButtonDesar;
	}

	/**
	 * This method initializes jButtonDescartar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonSortir() {
		if (jButtonSortir == null) {
			jButtonSortir = new JButton();
			jButtonSortir.setBounds(new Rectangle(16, 350, 100, 25));
			jButtonSortir.setText(Util.GetEtiqueta("Event.gestio.Sortir"));
			jButtonSortir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Client.escriptori.DeixarEscriptoriSensePanells();
				}
			});

			
		}
		return jButtonSortir;
	}

	/**
	 * This method initializes jButtonModificaPrerequisits	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonModificaPrerequisits() {
		if (jButtonModificaPrerequisits == null) {
			jButtonModificaPrerequisits = new JButton();
			jButtonModificaPrerequisits.setBounds(new Rectangle(370, 195, 95, 20));
			jButtonModificaPrerequisits.setText(Util.GetEtiqueta("Event.gestio.Modificar"));
		}
		return jButtonModificaPrerequisits;
	}

	/**
	 * This method initializes jCheckBoxActiu	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBoxActiu() {
		if (jCheckBoxActiu == null) {
			jCheckBoxActiu = new JCheckBox();
			jCheckBoxActiu.setBounds(new Rectangle(16, 316, 21, 21));
		}
		return jCheckBoxActiu;
	}

	/**
	 * This method initializes jButtonBorrarCamps	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonBorrarCamps() {
		if (jButtonBorrarCamps == null) {
			jButtonBorrarCamps = new JButton();
			jButtonBorrarCamps.setBounds(new Rectangle(225, 350, 200, 25));
			jButtonBorrarCamps.setText(Util.GetEtiqueta("Event.gestio.NetejarCamps"));
			jButtonBorrarCamps.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed (
					java.awt.event.ActionEvent e){
					BuidarCamps();				}
			});
		}
		return jButtonBorrarCamps;
	}
	
	/**
	* 
	* Metode per buidar la pantalla quan creem un nou.
	*
	**/
	
	private void BuidarCamps(){
		
		jTextFieldNom.setText("");
		jTextFieldDataInici.setText("");
		jTextFieldDataFi.setText("");
		jTextFieldInscripcioInici.setText("");
		jTextFieldInscripcioFi.setText("");
		jTextFieldPreu.setText("");
		jTextFieldPercentMinNoModif.setText("");
		jTextFieldPlaces.setText("");
		jComboBoxTipusEvent.setSelectedIndex(1);
		jTextAreaDescripcio.setText("");
		jCheckBoxEstudiant.setSelected(false);
		jCheckBoxDocent.setSelected(false);
		jCheckBoxNoDocent.setSelected(false);
		jCheckBoxAltres.setSelected(false);
		jCheckBoxActiu.setSelected(false);		
		// queda pendent netejar la taula jTablePrerequisits
		
	}
	 
	// activa o decativa camps per modificacio o consulta o nou segons calgui
	
	private void ActDescCamps(boolean Activacio){
		jTextFieldCodiCentre.setEnabled(false);
		jTextFieldCentreDocent.setEnabled(false);
		jTextFieldNom.setEnabled(Activacio);
		jTextFieldDataInici.setEnabled(Activacio);
		jTextFieldDataFi.setEnabled(Activacio);
		jTextFieldInscripcioInici.setEnabled(Activacio);
		jTextFieldInscripcioFi.setEnabled(Activacio);
		jTextFieldPreu.setEnabled(Activacio);
		jTextFieldPercentMinNoModif.setEnabled(Activacio);
		jTextFieldPlaces.setEnabled(Activacio);
		jComboBoxTipusEvent.setEnabled(Activacio);
		jTextAreaDescripcio.setEnabled(Activacio);
		jCheckBoxEstudiant.setEnabled(Activacio);
		jCheckBoxDocent.setEnabled(Activacio);
		jCheckBoxNoDocent.setEnabled(Activacio);
		jCheckBoxAltres.setEnabled(Activacio);
		jCheckBoxActiu.setEnabled(Activacio);	
	
		
	}
	
	private void NouEvent(){
		BuidarCamps();
		ActDescCamps(true);	
		jTextFieldCodiCentre.setText(Integer.toString(Client.usuariConnectat.getId_Centre()));
	//	jTextFieldCentreDocent.setText(Client.usuariConnectat.getCentreDocent().getNom());
		jButtonDesar.setEnabled(true);
		jButtonSortir.setEnabled(true);
		jButtonModificaPrerequisits.setEnabled(true);
		jButtonBorrarCamps.setEnabled(true);
		operacio = NOU;
				
	}
	
	
	private void ModificacioEvent(int id_event){
		ActDescCamps(true);	
		try {
			omplirEvent(id_event);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		jButtonDesar.setEnabled(true);
		jButtonSortir.setEnabled(true);
		jButtonModificaPrerequisits.setEnabled(true);
		jButtonBorrarCamps.setEnabled(true);
		jButtonDesar.setText(Util.GetEtiqueta("Event.gestio.modificar"));
		operacio = MODIFICAR;
				
	}
	
	private void VeureEvent(int id_event){
		ActDescCamps(false);	
		try {
			omplirEvent(id_event);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		jButtonDesar.setEnabled(false);
		jButtonSortir.setEnabled(true);
		jButtonModificaPrerequisits.setEnabled(false);
		jButtonBorrarCamps.setEnabled(false);
		operacio = VEURE;
				
	}

	/**
	* 
	* Metode per omplir la pantalla amb l'esdeveniment seleccionat 
	 * @throws RemoteException 
	*
	**/
	
	private void omplirEvent(int id_event) throws RemoteException{
		// Recuperar de BBDD el event
		try{
			//EventAux event = (EventAux) GestorRMI.rmi.getEventById(id_event);
			GestorEvent event = (GestorEvent) GestorRMI.rmi.getEventById(id_event);
			
		// Emplenar els camps
	//	SimpleDateFormat sdf = new SimpleDateFormat ("dd/MM/yyyy");
		jTextFieldCentreDocent.setText(event.getCentre().getNom());
		jTextFieldCodiCentre.setText(Integer.toString(event.getCentre().getId_centre()));
		jTextFieldNom.setText(event.getNom());
		jTextFieldDataInici.setText(sdf.format(event.getDataIni()));
		jTextFieldDataFi.setText(sdf.format(event.getDataFi()));
		jTextFieldInscripcioInici.setText(sdf.format(event.getDataIniInscripcio()));
		jTextFieldInscripcioFi.setText(sdf.format(event.getDataFiInscripcio()));
		jTextFieldPreu.setText(Double.toString(event.getPreu()));
		jTextFieldPercentMinNoModif.setText(Double.toString(event.getPercentMinNoModif()));
		jTextFieldPlaces.setText(Integer.toString(event.getCapacitatMax()));
		jComboBoxTipusEvent.setSelectedIndex(event.getId_tipusevent());
		jTextAreaDescripcio.setText(event.getDescripcio());
		
		// Check box
		jCheckBoxEstudiant.setSelected(false);
		jCheckBoxDocent.setSelected(false);
		jCheckBoxNoDocent.setSelected(false);
		jCheckBoxAltres.setSelected(false);
		
		ArrayList<EnumRol> rolList = event.getRolList();
		for (EnumRol item: rolList){
			if ("ALUMNE".equals(item.name())) {
				jCheckBoxEstudiant.setSelected(true);
			}
			if ("DOCENT".equals(item.name())) {
				jCheckBoxDocent.setSelected(true);
			}
			if ("EMPLEAT_NO_DOCENT".equals(item.name())) {
				jCheckBoxNoDocent.setSelected(true);
			}
			if ("ALTRE_PERSONAL".equals(item.name())) {
				jCheckBoxAltres.setSelected(true);
			}
		}
		
		jCheckBoxActiu.setSelected(event.isActiu());	
		}catch (RemoteException e){
			
		}
	}
	
	

} 
